package com.example.admin.SQLite.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.example.admin.SQLite.HfBean;
import com.example.admin.SQLite.ScBean;
import com.example.admin.SQLite.SqLiteOpenHelper;

import java.util.ArrayList;

import static com.example.admin.SQLite.SqLiteOpenHelper.TABLE_HF;
import static com.example.admin.SQLite.SqLiteOpenHelper.TABLE_SC;

public class ScBeanDao {
    SqLiteOpenHelper dbHelper;
    private static final String KEY_ID = "id";

    public ScBeanDao(Context context) {
        dbHelper = new SqLiteOpenHelper(context);
    }
    public ArrayList<ScBean> FindWhereSC(String ids, String uids) {
        String selection = "ids=? and uids=?"; // userName为要查询的列名
        String[] selectionArgs = {ids, uids}; // value为要查询的值

        SQLiteDatabase db = dbHelper.getSqlite();
        Cursor cursor = db.query(TABLE_SC, null, selection, selectionArgs, null, null, null);

        ArrayList<ScBean> arrContacts = new ArrayList<>();

        while (cursor.moveToNext()) {
            ScBean model = new ScBean();
            model.id = cursor.getInt(0);
            model.ids = cursor.getInt(1);
            model.uids = cursor.getInt(2);

            arrContacts.add(model);

        }
        return arrContacts;
    }
    public long addDataSc(ScBean bean) {
        SQLiteDatabase db = dbHelper.getSqlite();
        ContentValues values = new ContentValues();
        values.put("ids", bean.ids);
        values.put("uids", bean.uids);
        long id = db.insert(TABLE_SC, null, values);
        return id;
    }
    public void DeleteSc(int id) {
        SQLiteDatabase database = dbHelper.getSqlite();
        database.delete(TABLE_SC, KEY_ID + " = ? ", new String[]{String.valueOf(id)});
    }

    public ArrayList<HfBean> FindWhereHf(String ids) {
        String selection = "ids=?"; // userName为要查询的列名
        String[] selectionArgs = {ids}; // value为要查询的值

        SQLiteDatabase db = dbHelper.getSqlite();
        Cursor cursor = db.query(TABLE_HF, null, selection, selectionArgs, null, null, null);

        ArrayList<HfBean> arrContacts = new ArrayList<>();

        while (cursor.moveToNext()) {
            HfBean model = new HfBean();
            model.id = cursor.getInt(0);
            model.ids = cursor.getInt(1);
            model.cont = cursor.getString(2);
            model.uids = cursor.getString(3);
            model.datas = cursor.getString(4);

            arrContacts.add(model);

        }
        return arrContacts;
    }
    public long addDataHf(HfBean bean) {
        SQLiteDatabase db = dbHelper.getSqlite();
        ContentValues values = new ContentValues();
        values.put("ids", bean.ids);
        values.put("cont", bean.cont);
        values.put("uids", bean.uids);
        values.put("datas", bean.datas);
        long id = db.insert(TABLE_HF, null, values);
        return id;
    }
    public ArrayList<ScBean> FindWhereSC1(String uids) {
        String selection = "uids=?"; // userName为要查询的列名
        String[] selectionArgs = {uids}; // value为要查询的值

        SQLiteDatabase db = dbHelper.getSqlite();
        Cursor cursor = db.query(TABLE_SC, null, selection, selectionArgs, null, null, null);

        ArrayList<ScBean> arrContacts = new ArrayList<>();

        while (cursor.moveToNext()) {
            ScBean model = new ScBean();
            model.id = cursor.getInt(0);
            model.ids = cursor.getInt(1);
            model.uids = cursor.getInt(2);

            arrContacts.add(model);

        }
        return arrContacts;
    }


}
